﻿#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#define TOTAL_THREADS 5

int vetor[TOTAL_THREADS];

void *calcula(void *i) {
    
    int id = (int) i;
    while (vetor[id] != 0) {
        vetor[id] -= 1;
    }
    
    printf("Eu %d acabei =)\n", id);
    pthread_exit(NULL);
}

int main(void) {
    int i;
    
    pthread_t threads[TOTAL_THREADS];
    
    for (i=0; i<TOTAL_THREADS; i++) {
        vetor[i] = 20;
    }    
    
    for (i=0; i<TOTAL_THREADS; i++) {
        pthread_create(&threads[i], NULL, calcula, (void *) i);
    }
    
    pthread_exit(NULL);
}
